﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Web;

namespace SmartSpace.News.UI.Pages
{
    public partial class CreateArticle : System.Web.UI.Page
    {
        private Guid _categoryId { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            _categoryId = Guid.Parse(Request.QueryString["news_category_id"]);
        }

        protected void _ctlBtnSave_Click(object sender, EventArgs e)
        {
            NewsService service = new NewsService();

            Article article = new Article();
            article.Id = Guid.NewGuid();
            article.Code = _ctlCode.Text;
            article.CategoryId = _categoryId;
            article.Title = _ctlTitle.Text;
            article.Description = _ctlDesc.Text;
            article.Content = _ctlContent.Text;
            article.Creator = Page.User.Identity.Name;
            article.CreateDate = DateTime.Now;

            service.SaveArticle(article);

            SsPage.Return(this, new { id = article.Id });
        }
    }
}